import Vue from 'vue'
import App from './App.vue'
import './registerServiceWorker'
import router from './router'
import store from './store'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import VueAMap from 'vue-amap'
import infiniteScroll from 'vue-infinite-scroll'
import websocket from 'vue-native-websocket'
import mixin from '@/libs/mixin.js'

Vue.mixin(mixin)
Vue.config.productionTip = false
Vue.use(ElementUI)
Vue.use(VueAMap)
Vue.use(infiniteScroll)
Vue.use(websocket,'', {
  connectManually: true, // 手动连接
  format: 'json', // json格式
  reconnection: true, // 是否自动重连
  reconnectionAttempts: 5, // 自动重连次数
  reconnectionDelay: 2000, // 重连间隔时间
})

VueAMap.initAMapApiLoader({
  key: '5929bec9325020683ff092e74ee84ac6',
  plugin: ['AMap.Autocomplete','AMap.Geocoder', 'AMap.PlaceSearch', 'AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.AMapManager','AMap.Geolocation'],
  v: '1.4.4',
  uiVersion: '1.0.11'
})
router.beforeEach((to,from,next)=>{
  let isLogin = sessionStorage.getItem('accessToken')
  if(to.name == 'login' || to.name == 'enroll'){
    next()
    return
  }
  if(!isLogin){
    ElementUI.Message({
      message:'请先登录系统',
      type:'error'
    })
    next({
      name:'login'
    })
  }else{
    next()
  }
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
